<template>
  <!--用户账号-->
  <div>
    <div class="search">
      <input type="text" placeholder="用户账号/手机号搜索" v-model="searchContent">
      <img src="../../assets/search.png" alt="" width="16" @click="goSearch()">
    </div>
    <div class="page-infinite-wrapper" ref="wrapper" :style="{ height: wrapperHeight + 'px' }">
      <wv-group
        v-infinite-scroll="getList"
        infinite-scroll-disabled="loading"
        infinite-scroll-distance="10"
      >
        <ul class="list">
          <li v-for="(item,index) in accountList">
            <ul>
              <li>{{item.accountName}}</li>
              <li>地区：{{item.airportName}}</li>
              <li><span>注册时间：{{ item.createDate }}</span>
                <wv-button type="default" :mini="true" class="lookdetail" @click="showUntyingOpenId(item.accountId)">解绑
                </wv-button>
                <wv-button type="default" :mini="true" class="lookdetail" @click="resetPassword(item.accountId)">
                  重置密码
                </wv-button>
              </li>
            </ul>
          </li>
        </ul>
      </wv-group>
    </div>
    <div class="model" v-show="isVisible">
      <div class="bg"></div>
      <div class="modelsearchContent">
        <img src="../../assets/close.png" alt="" width="15" @click="isVisible=false">
       是否解绑微信
        <p class="btn">
          <button @click="goUntyingOpenId()">确定</button>
          <button @click="isVisible=false">取消</button>
        </p>
      </div>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
import {getAccountList, resetUserPassPassword, untyingOpenId} from '../../../test/unit/http'
import {Toast} from 'we-vue'

export default {
  name: '',
  props: {},
  data() {
    return {
      isVisible: false,
      accountList: [],
      searchContent: '',
      wrapperHeight: 0,
      page: 1,
      rows: 10,
      loading: false,
      pages: 0,
      totalNum: 0,
      accountId: ''
    };
  },
  methods: {
    getList() {
      let params = {
        page: this.page,
        rows: this.rows,
        searchContent: this.searchContent
      };
      getAccountList(params).then(res => {
        console.log(res);
        if (res.code == 100) {
          let data = res.object;
          let list = data.rows;
          let pages = data.pages;
          let page = data.page;
            this.page = page;
            this.pages = pages;
            let totalNum = data.totalNum;
            this.totalNum = totalNum;
            if (list.length > 0) {
              this.accountList = this.accountList.concat(list);
            }
          if (this.page < this.pages) {
            this.page++;
            this.loading = false
          } else {
            this.loading = true
          }
        } else {
          Toast.text(res.info);
        }
      })
    },
    goSearch() {
      this.page = 1;
      this.accountList = [];
      this.getList();
    },
    showUntyingOpenId(accountId) {
      this.accountId = accountId
      this.isVisible = true
    },
    goUntyingOpenId() {
      untyingOpenId({accountId: this.accountId}).then(res => {
        console.log(res);
        if (res.code == 100) {
          this.isVisible = false
          Toast.text('解绑成功');
          this.$router.go(-1)
        }
      })
    },
    resetPassword(accountId) {
      resetUserPassPassword({accountId: accountId}).then(res => {
        console.log(res);
        if (res.code == 100) {
          Toast.text('重置密码成功');
        }
      })
    }
  },
  created() {
  },
  components: {}
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less" rel="stylesheet/less">
  .bg {
    background-color: rgba(0, 0, 0, 0.3);
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 50px;
  }

  .model .modelsearchContent {
    background-color: #fff;
    border-radius: 8px;
    position: fixed;
    left: 50%;
    top: 50%;
    margin-left: -43%;
    margin-top: -111px;
    z-index: 2;
    padding: 40px 10px 20px;
    width: 80%;
    text-align: left;

    img {
      position: absolute;
      right: 10px;
      top: 10px
    }

    .btn {
      text-align: center;

      button {
        height: 42px;
        line-height: 42px;
        color: #fff;
        outline: none;
        border: none;
        width: calc(50% - 20px);
        border-radius: 8px;
        margin-top: 25px;
      }

      button:last-child {
        background-color: #ccc;
        border: 1px solid #ccc;
      }

      button:first-child {
        background-color: #f98e3c;
        margin-right: 20px;

      }
    }


  }

  .search {
    position: relative;
    width: 95%;
    margin: 10px auto;

    input {
      width: 90%;
      border: 1px solid #eee;
      box-shadow: 0 3px 4px rgba(17, 17, 17, 0.05);
      border-radius: 7px;
      height: 25px;
      line-height: 25px;
      padding: 10px;
      color: #111;
    }

    img {
      position: absolute;
      right: 20px;
      top: 16px;
    }
  }

  .list {
    padding: 10px 15px;
    text-align: left;

    > li {
      border-bottom: 1px solid #ddd;
      margin-bottom: 10px;

      li:first-child {
        font-size: 16px;
        color: #111;
        font-weight: 700;
        margin-bottom: 5px;

        span {
          color: #999;
          margin-left: 10px;
        }
      }

      li:nth-child(2), li:last-child {
        font-size: 12px;
        color: #666;
      }

      li:last-child {
        button {
          margin-left: 10px;
          background-color: #fb556a;
          color: #fff;
          height: 35px;
        }

        .dongjie {
          background-color: #f9d0d5;
          width: 90px;
        }

        span {
          flex: 0 70%;
          margin-top: 6px;
        }
      }
    }

    > li:last-child {
      border-bottom: none;
    }
  }
</style>
